package com.tedu;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * 爬虫的数据持久化  单独线程进行数据持久化
 */
public class PipelinesImpl extends JDBCUtill implements Pipeline {
    public void process(ResultItems resultItems, Task task) {
        //取出页面解析组件的值
        try
        {
            Object title_tex = resultItems.get("title_tex");
            Object time_tex = resultItems.get("time_tex");
            Object time_ly = resultItems.get("time_ly");
            Object elementsByClass = resultItems.get("elementsByClass");
            Object bj = resultItems.get("bj");
            Object currChnlCls = resultItems.get("currChnlCls");
            //对数据进行处理
            String[] split = time_tex.toString().split("：");
            String time = split[split.length-1];

            String[] split1 = time_ly.toString().split("：");
            String ly = split1[split1.length-1];

            String[] split2 = bj.toString().split("：");
            String auhtor = split2[split2.length-1];

            String[] s = currChnlCls.toString().split(" ");
            String type = s[s.length-1];

            System.out.println("爬虫的数据持久化："+title_tex);
            System.out.println("爬虫的数据持久化：time_tex:"+time);
            System.out.println("爬虫的数据持久化：time_ly"+ly);
            System.out.println("爬虫的数据持久化：bj"+auhtor);
            System.out.println("爬虫的数据持久化：currChnlCls"+type);
            System.out.println("爬虫的数据持久化：elementsByClass"+elementsByClass);

            //取出其他值，看看
            //调用jdbc完成数据持久化
            add("SQL",title_tex,time,ly,elementsByClass,auhtor,type);
        }catch (Exception e){

        }





    }
}
